import Vue from 'vue'
import Router from 'vue-router'
import {constantRoutes} from './routes'

Vue.use(Router)

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes // 静态注册
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  // 创建新的路由器(只注册了常量路由)
  const newRouter = createRouter()
  // matcher中包含了所有注册的路由
  router.matcher = newRouter.matcher // reset router

  // router.setRouters(constantRoutes)
  // router.removeRoute(route) // vue-router4  删除权限路由
}

export default router

// router.addRoutes(asyncRoutes)
